// pages/fullStock/search/search.js
var app =getApp();
import{
  allNetwork
}from "../../../api.js"
Page({

  /**
   * 页面的初始数据
   */
  data: {
    total:"",
    token:"",
    list:[],
    type:[
      {
        id:0,
        title:"Louis Vuitton"
      },{
        id: 1,
        title:"四叶草"
      },{
        id: 2,
        title:"Hermes"
      },
     {
        id: 4,
        title:"Celine"
      },{
        id: 5,
        title:"Chloe"
      },{
        id: 6,
        title:'购物袋'
      },{
        id: 7,
        title:"邮差包"
      }
    ],
    before:true,
    content:false,
    searchtext:"",
    lasttit:"",
    currpage:1,
    lastpage:2,
    full_name:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.token = app.globalData.token
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
    wx.stopPullDownRefresh()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var full_name = this.data.full_name
    console.log(full_name)
    var page=this.data.currpage+1
    if(page>this.data.lastpage){
      return
    }
    this.AllShopList({
      full_name: full_name,
      page
    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  clear(){
    this.setData({
      searchtext:""
    })
  },
  searchTab(e){
    var i = e.currentTarget.dataset.i
    this.data.type.forEach(r=>{
      if(r.id==i){
        this.setData({
          full_name:r.title
        })
        this.AllShopList({
          full_name:this.data.full_name
        })
      }
    })
    console.log(this.data.full_name)
  },
  toBuy(e) {
    let id = e.currentTarget.dataset.id;
    let is_synchronize = e.currentTarget.dataset.is_synchronize
    wx.navigateTo({
      url: '/pages/goodControl/toBuy/toBuy?id=' + id + '&is_synchronize=' + is_synchronize,
    })
  },
  searchtext(e){
    this.setData({
      full_name:e.detail.value,
      searchtext: e.detail.value
    })
  },
  search(){
    var full_name = this.data.full_name
    if (this.data.searchtext==""){
      return
    }
    this.AllShopList({
      full_name
    })
  },
  // 获取商品列表信息接口调用
  AllShopList(obj) {
    allNetwork({
      token: this.data.token,
      ...obj
    }).then(res => {
      if (res.data.code === 666) {
        if (res.data.data == null) {
          this.setData({
            list: [],
            before:false,
            content:false
          })
        } else {
          if (res.data.data.current_page == 1) {
            console.log(res)
            this.setData({
              list: res.data.data.data
            })
          } else {
            this.setData({
              list: this.data.list.concat(res.data.data.data)
            })
          }
          this.setData({
            internet: true,
            load: true,
            currpage: res.data.data.current_page,
            lastpage: res.data.data.last_page,
            lasttit: "",
            content: true,
            total: res.data.data.total
          })

        }
      } else if (res.data.code == 111111) {
        wx.showToast({
          title: '登录失效，请重新登录',
          icon: 'none',
        })
        setTimeout(function () {
          wx.reLaunch({
            url: '/pages/user/login/login',
          })
        }, 1500)
      } else {
        this.setData({
          lasttit: "暂无更多数据"
        })
      }
    })
  }
})